package com.example.demo.mvvm.ui.activity;

import android.view.Menu;
import android.view.MenuItem;

import com.example.demo.mvvm.BR;
import com.example.demo.mvvm.R;
import com.example.demo.mvvm.databinding.ActivityMainBinding;
import com.example.demo.mvvm.ui.base.BaseActivity;
import com.example.demo.mvvm.ui.fragment.SearchFragment;
import com.example.demo.mvvm.ui.vm.activity.MainVM;
import com.example.demo.mvvm.utils.ActivityUtils;

public class MainActivity extends BaseActivity<ActivityMainBinding , MainVM> {

    @Override
    protected void init() {
        setSupportActionBar(databing.toolBar);
    }

    @Override
    public int getLayoutId() {
        return  R.layout.activity_main;
    }

    @Override
    public int getVariableId() {
        return BR.viewModel;
    }

    @Override
    public MainVM getViewModel() {
        return new MainVM(databing , getSupportFragmentManager());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menuSearch:
                SearchFragment mSearchFragemnt = new SearchFragment();
                mSearchFragemnt.show(getSupportFragmentManager() , "searchFragment");
                break;
            case R.id.menuHot:
                ActivityUtils.push(ActivityUtils.peek() , LoginActivity.class);
                break;
            default:
                break;
        }


        return super.onOptionsItemSelected(item);
    }
}
